package com.example.reader.controller;

import com.example.reader.common.Result;
import com.example.reader.entity.Cart;
import com.example.reader.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/cart")
public class CartController {
    @Autowired
    private CartService cartService;

    //加入书单
    @PostMapping("/add")
    public Result add(@RequestBody Cart cart) {
        cartService.add(cart);
        return Result.success();
    }

    //查看所有
    @GetMapping("/selectAll")
    public Result selectAll(Cart cart) {
        List<Cart> list = cartService.selectAll(cart);
        return Result.success(list);
    }

    //单个删除
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        cartService.deletebyid(id);
        return Result.success();
    }

    //批量删除
    @DeleteMapping("/delete/batch")
    public Result delete(@PathVariable Integer[] ids) {
        cartService.deleteBatch(ids);
        return Result.success();
    }

}
